import QtQuick 2.0
import QtQuick.Controls 2.5

import "../basic"

Item {
    id: checkBox
    enabled: true
    height: 25
    width: rect.width + label.width + 10

    property string text: qsTr("记住密码")
    property color textColor: "#ddd"
    property int textFormat: 0      // 0表示默认，1表示富文本
    property bool isSelected: false

    Component.onCompleted: {
        if (isSelected) {
            rect.selected = isSelected;
        }
    }

    MouseArea {
        anchors.fill: parent
        hoverEnabled: true
        onPressed: {
            rect.selected = !rect.selected
        }
        onEntered: {
            cursorShape: checkBox.enabled ? Qt.PointingHandCursor : Qt.ForbiddenCursor
        }
        onExited: {
            cursorShape: Qt.ArrowCursor
        }
    }

    Row {
        anchors.left: parent.left
        anchors.verticalCenter: parent.verticalCenter
        spacing: 7
        Rectangle {
            id: rect
            width: 20
            height: width
            radius: 2
            color: selected ? "#eb4d44" : "transparent"
            border.width: 1
            border.color: "#2f2f34"
            property bool selected: false
            Label {
                id: selectedLabel
                visible: parent.selected
                color: "white"
                font.bold: true
                text: "✔"
                font.pixelSize: 18
                font.family: BasicConfig.commFont
                anchors.centerIn: parent
            }
        }
        Label {
            id: label
            color: checkBox.enabled ? checkBox.textColor : "#2f2f34"
            font.bold: true
            text: checkBox.text
            font.pixelSize: 18
            font.family: BasicConfig.commFont
            anchors.top: rect.top
            anchors.topMargin: -3

            textFormat: checkBox.textFormat === 0 ? Text.Normal : Text.RichText
        }
    }
}
